﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Talentnet.Core.Web;
using Talentnet.Core.Utilities.Cryptophy;

[PageTextResource("ResetPwd")]
public partial class resetPwd : NormalPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        
        ctrlResetPwdHolder.Visible = !SessionManager.ResetPwd;
        if (SessionManager.PwdExpired)
        {
            ctrlMsg.Text = LoadText("ResetPwd", "msg1");
            ctrlCont.Visible = false;
        }
        else if (SessionManager.PwdNearlyExpired)
        {
            ctrlMsg.Text = LoadText("ResetPwd", "msg2");
        }
        else
        {
            ctrlMsg.Text = "";
        }
    }
    //ctrlCont_Click
    protected void ctrlCont_Click(object sender, EventArgs e)
    {
        SessionManager.PwdExpired = SessionManager.PwdNearlyExpired = false;
        Response.Redirect("~/default.aspx");
    }
    protected void ctrlOK_Click(object sender, EventArgs e)
    {
        if (inPassword.Text != inConfirm.Text)
        {
            return;
        }
        int ret = DBUser.UserChangePwd(SessionManager.CurrentUser.RecId, ctrlResetPwdHolder.Visible ? CryptoAgent.Current.MD5(inCurPwd.Text) : null, CryptoAgent.Current.MD5(inPassword.Text));
        switch (ret)
        {
            case 1:
                SessionManager.PwdExpired = SessionManager.PwdNearlyExpired = false;
                Response.Redirect("~/default.aspx");
                break;
            case 2:
                ClientScript.RegisterStartupScript(GetType(), "msg", "alert('" + LoadText("ResetPwd", "msg3") + "');", true);
                break;
            case 3:
                ClientScript.RegisterStartupScript(GetType(), "msg", "alert('" + LoadText("ResetPwd", "msg4") + "');", true);
                break;
        }
        
    }
}
